#ifndef SENDEVENT_H
#define SENDEVENT_H

#include <QObject>
#include <QDebug>
#include <QThread>
#include <QApplication>

class SendEvent : public QObject
{
    Q_OBJECT
public:
    void userSendEvent()
    {
        qDebug() << "void userSendEvent() in SendEvent class " << QThread::currentThread();
        QApplication::sendEvent(receiverObj,new QEvent(QEvent::User));
        // 先调用SendReceiver::event,在往下执行
        qDebug() << "QApplication::sendEvent 同步调用";
    }
public:
    QObject* receiverObj;
};

class SendReceiver : public QObject
{
    Q_OBJECT
protected:
    bool event(QEvent *event) override
    {
        if(event->type() == QEvent::User)
        {
            qDebug() << "SendReceiver in main " << QThread::currentThread();
            return true;
        }
        return QObject::event(event);
    }
};

#endif // SENDEVENT_H
